package com.example.li.myapplication.base;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by ly on 2016/9/29 16:55.
 */

public abstract class MvpFragment<P extends IPresenter> extends Fragment implements IView {
   protected P p ;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        p = bindPresenter();
        if (p != null) {
            p.attachView(this);
        }
        super.onViewCreated(view, savedInstanceState);
    }

    protected abstract P bindPresenter();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (p != null) {
            p.detachView(this);
        }
    }
}
